<template>
	<view>
		<my-tabs v-if = "tabModelData.length>0" @change="tapChange" :modelData="tabModelData" :initIndex="initTabIndex"></my-tabs>
		<scroll-view class="purchase-body" scroll-y="true" @scrolltolower="scrolltolower" @scrolltoupper="scrolltoupper" @scroll="scroll" @touchstart="touchstart" @touchend="touchend">
			<my-unit v-for="(item,index) in listData" :key="index" :unitName="unitName" :infoArray="[item]" :idx="index"></my-unit>
		</scroll-view>
	</view>
</template>

<script>
	import myTabs from '@/components/myTabs/myTabs.vue'
	import myUnit from '@/components/myUnits/purchaseUnit/unit.vue'
	import myPull from '@/static/js/myPull.js'
	import myLoading from '@/components/myLoading/myLoading.vue'
	

	export default {
		components: {
			myTabs,
			myUnit,
			myLoading
		},
		data() {
			return {
				unitName: 'dirverUnit',
				initTabIndex:0,
				tabModelData:[
					{
						label:"全部",
						badge:"0",
						passStatus: 0
					},
					{
						label:"待审核",
						badge:"0",
						passStatus: 2
					},
					{
						label:"通过",
						badge:"0",
						passStatus: 4
					},
					{
						label:"拒绝",
						badge:"0",
						passStatus: 5
					},
					{
						label:"过期",
						badge:"0",
						passStatus: 100
					},
				],
				pageSize:4,
				curPage:0,
				queryData:{},
				sumDataCount:0,
				// listData:[
					
				// ]
			}
		},
		
		onShow(){
			this.getList();
		},
		mixins:[myPull({})],
		methods: {
			/**
			 * @name 改变tab
			 * @param val 索引
			 */
			tapChange(val){
				let _this = this;
				
				_this.initTabIndex=val
				console.log("tapChange initTabIndex:"+val);
				//this.modelData[val].badge++;
				
				_this.curPage = 0;
				_this.sumDataCount = 0;
				_this.listData = [];
				_this.getList();
			},
			change(e) {
			    this.current = e.detail.current;
			},
			
			refreshPage(){
				console.log("index refresh")
			},
			getList(){
				let _this = this;
				
				let params = {};
				let url = "/rest/passQuery";
				
				params.limit = _this.pageSize;
				params.page = _this.curPage+1;
				params.createTimeOrder = "DESC";
				
				// 非全部状态
				if(_this.initTabIndex>0){
					params.passCheckStatus = _this.tabModelData[_this.initTabIndex].passStatus;
				}
				
				_this.$api.request(url, params, failres => {
					uni.showToast({
						title: "服务器异常",
						icon: "none"
					});
				}).then(rsp => {
					//表单提交成功
					//提交图片
					console.log('获取表单数据成功:' + JSON.stringify(rsp));
					_this.sumDataCount = rsp.count;
					//_this.listData = rsp.data;
					_this.curPage++;
					
					_this.listData = (_this.listData || []).concat(rsp.data);
					//_this.tabModelData[_this.initTabIndex].badge = ''+_this.sumDataCount;
				})
			},
			
			/**
			 * @name 触底加载
			 */
			scrolltolower(event){
				console.log("scrolltolower...");
				//this.getList()
			},
			
			scroll(e){
				// 重新设置pulldown
				this.setPullDown(e.detail.scrollTop<10)
			},
			
			scrolltoupper(){
				
			},
		}
	}
</script>

<style>

</style>
